package com.gxa.community.customer.controller.mine;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.gxa.community.core.pojo.vo.order.AfterSalesVo;
import com.gxa.community.core.utils.LittleUtils;
import com.gxa.community.core.utils.R;
import com.gxa.community.customer.service.mine.MineService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mine")
public class MineController {
    // TODO 获取用户ID

    final MineService mineService;

    public MineController(MineService mineService) {
        this.mineService = mineService;
    }

    /**
     * 查询『我的』界面基础信息
     */
    @GetMapping("/getMineInfo")
    public R getMineInfo() {
        Integer uid = 10000;
        return mineService.getMineInfo(uid);
    }

    /**
     * 查询我的优惠券
     */
    @GetMapping("/queryCoupon")
    public R queryCoupon() {
        Integer uid = 10000;
        return mineService.queryCoupon(uid);
    }

    /**
     * 查询我的订单
     */
    @GetMapping("/queryOrder")
    public R queryOrder(Integer page, Integer size, Integer status) {
        if (page == null || page < 1) page = 1;
        if (size == null || size < 1 || size > 100) size = 5;

        Integer uid = 10000;
        return mineService.queryOrder(page, size, uid, status);
    }

    /**
     * 查询我的售后
     */
    @GetMapping("/queryAfterSales")
    public R queryAfterSales(Integer page, Integer size) {
        if (page == null || page < 1) page = 1;
        if (size == null || size < 1 || size > 100) size = 5;

        Integer uid = 10000;
        return mineService.queryAfterSales(page, size, uid);
    }

    /**
     * 新增售后
     */
    @PostMapping("/addAfterSales")
    public R addAfterSales(@RequestBody AfterSalesVo salesVo) {
        if (StringUtils.isBlank(salesVo.getOrderNo())) return R.error("订单编号不能为空");
        if (LittleUtils.checkNum(salesVo.getType(), 1, 3)) R.error("售后类型有误");
        if (StringUtils.isBlank(salesVo.getDesc())) return R.error("问题描述不能为空");
        if (StringUtils.isBlank(salesVo.getPic())) return R.error("截图凭证不能为空");
        if (LittleUtils.checkNum(salesVo.getRequestReason(), 1, 5)) return R.error("退款原因有误");

        Integer uid = 10000;
        return mineService.addAfterSales(salesVo.setUserId(uid));
    }


    /**
     * 根据订单编号查询订单内商品
     */
    @GetMapping("/queryGoods")
    public R queryGoods(@RequestBody List<String> orderNo) {
        Integer uid = 10000;
        return mineService.queryGoods(uid, orderNo);
    }
}
